function generateOrderId() {
    // 获取当前时间戳
    const timestamp = Date.now();
    // 生成4位随机数
    const randNum = Math.floor(Math.random() * 9000 + 1000);
    // 拼接为订单号
    const orderId = `${timestamp}${randNum}`;
    return orderId;
}
function getTime() {
    const now = new Date();
    const year = now.getFullYear();
    const month = String(now.getMonth() + 1).padStart(2, '0');
    const date = String(now.getDate()).padStart(2, '0');
    const hour = String(now.getHours()).padStart(2, '0');
    const minute = String(now.getMinutes()).padStart(2, '0');
    const second = String(now.getSeconds()).padStart(2, '0');

    const formattedDate = `${year}-${month}-${date} ${hour}:${minute}:${second}`;
    return formattedDate
    console.log(formattedDate); // 输出：2023-04-16 13:27:37
}

function timeHanle(time) {
    const dateObj = new Date(time);
    const year = dateObj.getFullYear();
    const month = ('0' + (dateObj.getMonth() + 1)).slice(-2); // 将月份补足两位数
    const day = ('0' + dateObj.getDate()).slice(-2); // 将日期补足两位数
    const hour = ('0' + dateObj.getHours()).slice(-2);  // 将小时补足两位数
    const minute = ('0' + dateObj.getMinutes()).slice(-2); // 将分钟补足两位数
    const second = ('0' + dateObj.getSeconds()).slice(-2); // 将秒数补足两位数
    const localTime = `${year}-${month}-${day} ${hour}:${minute}:${second}`;
    return localTime
}
function timeMD(time) {
    const time1 = new Date(time)
    const month = time1.getMonth() + 1
    const day = time1.getDate()
    return `${month}-${day}`
}
module.exports = {
    generateOrderId,
    getTime,
    timeHanle,
    timeMD
};